####SubGroupExpenses####

import SubGroupExpensesTable
import PeopleInSubGroupTable

class SubGroupExpenses(SubGroupExpensesTable.SubGroupExpenseDetails, PeopleInSubGroupTable.PeopleInSubGroup):
    def __init__(self, MySQLObj):
        self.SQLObj = MySQLObj
        SubGroupExpensesTable.SubGroupExpenseDetails.__init__(self, MySQLObj)
        PeopleInSubGroupTable.PeopleInSubGroup.__init__(self, MySQLObj)
    
    def AddSubGroupExpense(self, EID, PID, Desc, Amount, Date, AddedPIDs):
        self.AddSubGroupExpenseDetails(EID, PID, Date, Desc, Amount)
        Expense = self.GetSubGroupExpenses(EID=EID, PID=PID, Exp_Discription = Desc, Exp_Date = Date)[0]
        for PID, Prop in AddedPIDs:
            self.AddPersonToSubGroup(PID, Expense.EID, Expense.SgExp_id, Prop)
            
    def UpdateSubGroupExpense(self, Expense, PIDs):
        self.UpdateSubGroupExpenseDetails(Expense)
        self.RemoveSubGroup(Expense.SgExp_id)
        for PID, Prop in PIDs:
            self.AddPersonToSubGroup(PID, Expense.EID, Expense.SgExp_id, Prop)
        self.SubGroupExpenseUpdateStatus(Expense.SgExp_id)
    
    def GetSubgroupExpensesOfPerson(self, PID, EID):
        ##return [[SubGroupExpense, Prop],[[SubGroupExpense, Prop]]]
        SubGroupsExpenseIDs = self.GetAllSubGroupsPersonInOnEvent(PID, EID)
        SubGroupExpenses = self.GetAllSubGroupExpensesDict()
        Output = []
        for ExpenseID, Prop in SubGroupsExpenseIDs:
            Output.append([SubGroupExpenses[ExpenseID], Prop])
        return Output
    
    def RemoveSubGroupExpense(self, SgExpId):
        SubGroupExpensesTable.SubGroupExpenseDetails.RemoveSubGroupExpense(self, SgExpId)
        PeopleInSubGroupTable.PeopleInSubGroup.RemoveSubGroup(self, SgExpId)
        
        


def GenerateTables(MySql):
    import SubGroupExpensesTable

    SubGroupExpensesTable.GenerateTables(MySql)
    PeopleInSubGroupTable.GenerateTables(MySql)




    